/* NiallsCPP11Utilities
(C) 2012 Niall Douglas http://www.nedprod.com/
File Created: Nov 2012


Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

#include <stdexcept>
#include <string>

#if defined(BOOST_MSVC) && BOOST_MSVC<=1800 && !defined(__func__)
#define __func__ __FUNCTION__
#endif

#ifdef BOOST_AFIO_EXCEPTION_DISABLESOURCEINFO
#define BOOST_AFIO_EXCEPTION_FILE(p) (const char *) 0
#define BOOST_AFIO_EXCEPTION_FUNCTION(p) (const char *) 0
#define BOOST_AFIO_EXCEPTION_LINE(p) 0
#else
#define BOOST_AFIO_EXCEPTION_FILE(p) __FILE__
#define BOOST_AFIO_EXCEPTION_FUNCTION(p) __func__
#define BOOST_AFIO_EXCEPTION_LINE(p) __LINE__
#endif

BOOST_AFIO_V2_NAMESPACE_BEGIN
  class path;
  namespace detail{
    
#ifdef WIN32
                    BOOST_AFIO_HEADERS_ONLY_FUNC_SPEC void int_throwWinError(const char *file, const char *function, int lineno, unsigned code, std::function<BOOST_AFIO_V2_NAMESPACE::path()> filename);
                    extern "C" unsigned __stdcall GetLastError();
#define BOOST_AFIO_ERRGWIN(code)                { BOOST_AFIO_V2_NAMESPACE::detail::int_throwWinError(BOOST_AFIO_EXCEPTION_FILE(0), BOOST_AFIO_EXCEPTION_FUNCTION(0), BOOST_AFIO_EXCEPTION_LINE(0), code, nullptr); }
#define BOOST_AFIO_ERRGWINFN(code, filename)    { BOOST_AFIO_V2_NAMESPACE::detail::int_throwWinError(BOOST_AFIO_EXCEPTION_FILE(0), BOOST_AFIO_EXCEPTION_FUNCTION(0), BOOST_AFIO_EXCEPTION_LINE(0), code, std::function<BOOST_AFIO_V2_NAMESPACE::path()>(filename)); }
#define BOOST_AFIO_ERRHWIN(exp)             { unsigned __errcode=(unsigned)(exp); if(!__errcode) BOOST_AFIO_ERRGWIN(GetLastError()); }
#define BOOST_AFIO_ERRHWINFN(exp, filename) { unsigned __errcode=(unsigned)(exp); if(!__errcode) BOOST_AFIO_ERRGWINFN(GetLastError(), filename); }

                    BOOST_AFIO_HEADERS_ONLY_FUNC_SPEC void int_throwNTError(const char *file, const char *function, int lineno, unsigned code, std::function<BOOST_AFIO_V2_NAMESPACE::path()> filename);
#define BOOST_AFIO_ERRGNT(code)             { BOOST_AFIO_V2_NAMESPACE::detail::int_throwNTError(BOOST_AFIO_EXCEPTION_FILE(0), BOOST_AFIO_EXCEPTION_FUNCTION(0), BOOST_AFIO_EXCEPTION_LINE(0), code, nullptr); }
#define BOOST_AFIO_ERRGNTFN(code, filename) { BOOST_AFIO_V2_NAMESPACE::detail::int_throwNTError(BOOST_AFIO_EXCEPTION_FILE(0), BOOST_AFIO_EXCEPTION_FUNCTION(0), BOOST_AFIO_EXCEPTION_LINE(0), code, std::function<BOOST_AFIO_V2_NAMESPACE::path()>(filename)); }
#define BOOST_AFIO_ERRHNT(exp)              { unsigned __errcode=(unsigned)(exp); if(0/*STATUS_SUCCESS*/!=__errcode) BOOST_AFIO_ERRGNT(__errcode); }
#define BOOST_AFIO_ERRHNTFN(exp, filename)  { unsigned __errcode=(unsigned)(exp); if(0/*STATUS_SUCCESS*/!=__errcode) BOOST_AFIO_ERRGNTFN(__errcode, filename); }
#endif // WIN32

                    BOOST_AFIO_HEADERS_ONLY_FUNC_SPEC void int_throwOSError(const char *file, const char *function, int lineno, int code, std::function<BOOST_AFIO_V2_NAMESPACE::path()> filename);
#define BOOST_AFIO_ERRGOS(code)             { BOOST_AFIO_V2_NAMESPACE::detail::int_throwOSError(BOOST_AFIO_EXCEPTION_FILE(code), BOOST_AFIO_EXCEPTION_FUNCTION(code), BOOST_AFIO_EXCEPTION_LINE(code), code, nullptr); }
#define BOOST_AFIO_ERRGOSFN(code, filename) { BOOST_AFIO_V2_NAMESPACE::detail::int_throwOSError(BOOST_AFIO_EXCEPTION_FILE(code), BOOST_AFIO_EXCEPTION_FUNCTION(code), BOOST_AFIO_EXCEPTION_LINE(code), code, std::function<BOOST_AFIO_V2_NAMESPACE::path()>(filename)); }
            /*! Use this macro to wrap POSIX, UNIX or CLib functions. On BOOST_WINDOWS, the includes anything in
            MSVCRT which sets errno
            */
#define BOOST_AFIO_ERRHOS(exp)                  { int __errcode=(int)(exp); if(__errcode<0) BOOST_AFIO_ERRGOS(errno); }
            /*! Use this macro to wrap POSIX, UNIX or CLib functions taking a filename. On BOOST_WINDOWS, the includes anything in
            MSVCRT which sets errno
            */
#define BOOST_AFIO_ERRHOSFN(exp, filename)      { int __errcode=(int)(exp); if(__errcode<0) BOOST_AFIO_ERRGOSFN(errno, filename); }
  }//namespace detail

BOOST_AFIO_V2_NAMESPACE_END

